package com.mayuhao.userteacher.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mayuhao.userteacher.entity.CssChooseCourse;
import com.mayuhao.userteacher.entity.CssStudentVO;
import com.mayuhao.userteacher.entity.UserTeacher;
import com.mayuhao.userteacher.mapper.UserTeacherMapper;
import com.mayuhao.userteacher.service.IUserTeacherService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author 马宇豪
 * @since 2022-10-27
 */
@Service
public class UserTeacherServiceImpl extends ServiceImpl<UserTeacherMapper, CssChooseCourse> implements IUserTeacherService {
    @Resource
    private UserTeacherMapper teacherMapper;

    /**
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<com.mayuhao.userteacher.entity.UserTeacher>
     * @description 请修改方法描述
     * @methodName teacherCourse
     * @params [pageNum, pageSize, searchId, searchName]
     * @paramType [java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String]
     * @author 马宇豪
     * @date 2022/10/31 0031 下午 2:07
     * @email 1757442521@qq.com
     **/
    @Override
    public Page<UserTeacher> teacherCourse(Integer pageNum, Integer pageSize, String teacherId, String searchId, String searchName) {
        return teacherMapper.teacherCourse(new Page<>(pageNum, pageSize), teacherId, searchId, searchName);
    }

    /**
     * @return java.util.List<com.mayuhao.userteacher.entity.UserTeacher>
     * @description 请修改方法描述
     * @methodName selectCourse
     * @params [teacherId]
     * @paramType [java.lang.String]
     * @author 马宇豪
     * @date 2022/10/31 0031 下午 4:38
     * @email 1757442521@qq.com
     **/
    @Override
    public List<UserTeacher> selectCourse(String teacherId) {
        return teacherMapper.selectCourse(teacherId);
    }

    /**
     * @return java.util.List<com.mayuhao.userteacher.entity.CssStudentVO>
     * @description 请修改方法描述
     * @methodName boundStudent
     * @params [courseId]
     * @paramType [java.lang.String]
     * @author 马宇豪
     * @date 2022/10/31 0031 下午 5:26
     * @email 1757442521@qq.com
     **/
    @Override
    public Page<CssStudentVO> boundStudentPage(Integer pageNum, Integer pageSize, String courseId, String searchId, String searchName) {
        return teacherMapper.boundStudentPage(new Page<>(pageNum, pageSize), courseId, searchId, searchName);
    }

    /**
     * @description 请修改方法描述
     * @methodName myUpdate
     * @params [chooseCourse]
     * @paramType [com.mayuhao.userteacher.entity.CssChooseCourse]
     * @return boolean
     * @author 马宇豪
     * @date 2022/11/1 0001 上午 9:43
     * @email 1757442521@qq.com
     **/
    @Override
    public boolean myUpdate(CssChooseCourse chooseCourse) {
        LambdaUpdateWrapper<CssChooseCourse> wrapper = Wrappers.lambdaUpdate();
        wrapper.set(CssChooseCourse::getCourseScore, chooseCourse.getCourseScore()).
                eq(CssChooseCourse::getStudentId, chooseCourse.getStudentId()).
                eq(CssChooseCourse::getCourseId, chooseCourse.getCourseId());
        return update(wrapper);
    }
}
